$(function () {
    $.extend(jQuery.app, {
        /**
         * 权限控制，显示或隐藏按钮
         * @returns {[]}
         */
        controlPermission: function () {
            $.ajax({
                type: 'GET',
                url: '/security/authentication',
                dataType: 'json'
            }).done(function (data) {
                if (data.authenticated) {
                    var authorities = data.authorities;
                    var permission = [];
                    for(var i in authorities){
                        permission.push(authorities[i].authority);
                    }
                    $("[permission]").each(function () {
                        var per = $(this).attr("permission");
                        if ($.inArray(per, permission) < 0) {
                            $(this).hide();
                        } else {
                            $(this).show();
                        }
                    });
                }
            });
        }
    });
});